package com.itcast.activiti;

import com.alibaba.fastjson.JSON;
import com.itcast.activiti.utils.SecurityUtil;
import org.activiti.api.process.model.ProcessDefinition;
import org.activiti.api.process.model.ProcessInstance;
import org.activiti.api.process.model.builders.ProcessPayloadBuilder;
import org.activiti.api.process.model.payloads.GetProcessInstancesPayload;
import org.activiti.api.process.runtime.ProcessRuntime;
import org.activiti.api.runtime.shared.query.Page;
import org.activiti.api.runtime.shared.query.Pageable;
import org.activiti.api.task.model.Task;
import org.activiti.api.task.model.builders.TaskPayloadBuilder;
import org.activiti.api.task.model.payloads.CompleteTaskPayload;
import org.activiti.api.task.model.payloads.GetTasksPayload;
import org.activiti.api.task.runtime.TaskRuntime;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.history.HistoricVariableInstance;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * activiti7新特性测试
 */
@RunWith(SpringRunner.class)
@SpringBootTest
class ActivitiTest4 {
    /**
     * 流程定义相关操作
     */
    @Autowired
    private ProcessRuntime processRuntime;
    /**
     * 任务相关操作
     */
    @Autowired
    private TaskRuntime taskRuntime;
    /**
     * security工具类
     */
    @Autowired
    private SecurityUtil securityUtil;
    /**
     * 流程定义和部署存相关操作
     */
    @Autowired
    private RepositoryService repositoryService;
    /**
     * 历史信息相关操作
     */
    @Autowired
    private HistoryService historyService;

    /**
     * 自动部署流程
     * spring boot 会自动部署 processes文件中的bpmn
     */
    @Test
    public void deployAutomate() {
        // TODO 测试没通过有bug
        // 权限必须
        securityUtil.logInAs("salaboy");
        Page<ProcessDefinition> processDefinitionPage = processRuntime.processDefinitions(Pageable.of(0, 10));
        System.out.println(processDefinitionPage.getTotalItems());
        for (ProcessDefinition p : processDefinitionPage.getContent()) {
            System.out.println(JSON.toJSON(p));
        }
    }

    /**
     * 原生activiti手动部署流程
     */
    @Test
    public void deploy() {
        Map<String, String> map = new HashMap();
//        map.put("pmis_proj_project", "PMIS-项目审批流程");
//        map.put("pmis_proj_acceptance", "PMIS-项目验收审批工作流程");
//        map.put("pmis_proj_plan_direction", "PMIS-规划审批流程");
//        map.put("pmis_proj_task", "PMIS-任务审批流程");
//        map.put("pmis_resource", "PMIS-资源审批流程");
//        map.put("pmis_resource_release", "PMIS-资源发布审批流程");
//        map.put("pmis_leave_business", "PMIS-请假审批流程");
        map.put("pmis_contract", "PMIS-合同审批流程");
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String bpmnName = entry.getKey();
            String name = entry.getValue();
            DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().name(name);
            Deployment deployment = deploymentBuilder
                    .addClasspathResource("processes/" + bpmnName + ".bpmn")
//                    .addClasspathResource("processes/" + bpmnName + ".png")
                    .tenantId("PMIS")
                    .deploy();

            if (deployment != null) {
                System.out.println("原生activiti部署流程：" + JSON.toJSON(deployment));
                Map<String, Object> result = new HashMap<>(2);
                result.put("deployID", deployment.getId());
                result.put("deployName", deployment.getName());
                System.out.println(JSON.toJSON(result));
            }
        }
//        原生activiti部署流程：{"new":true,"resources":{"processes/pmisPublicActiviti.bpmn":{"deleted":false,"inserted":true,"generated":false,"bytes":[60,63,120,109,108,32,118,101,114,115,105,111,110,61,34,49,46,48,34,32,101,110,99,111,100,105,110,103,61,34,85,84,70,45,56,34,32,115,116,97,110,100,97,108,111,110,101,61,34,121,101,115,34,63,62,13,10,60,100,101,102,105,110,105,116,105,111,110,115,32,120,109,108,110,115,61,34,104,116,116,112,58,47,47,119,119,119,46,111,109,103,46,111,114,103,47,115,112,101,99,47,66,80,77,78,47,50,48,49,48,48,53,50,52,47,77,79,68,69,76,34,32,120,109,108,110,115,58,97,99,116,105,118,105,116,105,61,34,104,116,116,112,58,47,47,97,99,116,105,118,105,116,105,46,111,114,103,47,98,112,109,110,34,32,120,109,108,110,115,58,98,112,109,110,100,105,61,34,104,116,116,112,58,47,47,119,119,119,46,111,109,103,46,111,114,103,47,115,112,101,99,47,66,80,77,78,47,50,48,49,48,48,53,50,52,47,68,73,34,32,120,109,108,110,115,58,100,99,61,34,104,116,116,112,58,47,47,119,119,119,46,111,109,103,46,111,114,103,47,115,112,101,99,47,68,68,47,50,48,49,48,48,53,50,52,47,68,67,34,32,120,109,108,110,115,58,100,105,61,34,104,116,116,112,58,47,47,119,119,119,46,111,109,103,46,111,114,103,47,115,112,101,99,47,68,68,47,50,48,49,48,48,53,50,52,47,68,73,34,32,120,109,108,110,115,58,116,110,115,61,34,104,116,116,112,58,47,47,119,119,119,46,97,99,116,105,118,105,116,105,46,111,114,103,47,116,101,115,116,109,49,54,48,55,57,48,56,49,54,48,57,50,48,34,32,120,109,108,110,115,58,120,115,100,61,34,104,116,116,112,58,47,47,119,119,119,46,119,51,46,111,114,103,47,50,48,48,49,47,88,77,76,83,99,104,101,109,97,34,32,120,109,108,110,115,58,120,115,105,61,34,104,116,116,112,58,47,47,119,119,119,46,119,51,46,111,114,103,47,50,48,48,49,47,88,77,76,83,99,104,101,109,97,45,105,110,115,116,97,110,99,101,34,32,101,120,112,114,101,115,115,105,111,110,76,97,110,103,117,97,103,101,61,34,104,116,116,112,58,47,47,119,119,119,46,119,51,46,111,114,103,47,49,57,57,57,47,88,80,97,116,104,34,32,105,100,61,34,109,49,54,48,55,57,48,56,49,54,48,57,50,48,34,32,110,97,109,101,61,34,34,32,116,97,114,103,101,116,78,97,109,101,115,112,97,99,101,61,34,104,116,116,112,58,47,47,119,119,119,46,97,99,116,105,118,105,116,105,46,111,114,103,47,116,101,115,116,109,49,54,48,55,57,48,56,49,54,48,57,50,48,34,32,116,121,112,101,76,97,110,103,117,97,103,101,61,34,104,116,116,112,58,47,47,119,119,119,46,119,51,46,111,114,103,47,50,48,48,49,47,88,77,76,83,99,104,101,109,97,34,62,13,10,32,32,60,112,114,111,99,101,115,115,32,105,100,61,34,112,109,105,115,45,112,117,98,108,105,99,45,97,99,116,105,118,105,116,105,34,32,105,115,67,108,111,115,101,100,61,34,102,97,108,115,101,34,32,105,115,69,120,101,99,117,116,97,98,108,101,61,34,116,114,117,101,34,32,110,97,109,101,61,34,80,77,73,83,-23,-128,-102,-25,-108,-88,-27,-82,-95,-26,-119,-71,-26,-75,-127,-25,-88,-117,34,32,112,114,111,99,101,115,115,84,121,112,101,61,34,78,111,110,101,34,62,13,10,32,32,32,32,60,115,116,97,114,116,69,118,101,110,116,32,105,100,61,34,115,116,97,114,116,34,32,110,97,109,101,61,34,-27,-68,-128,-27,-89,-117,34,47,62,13,10,32,32,32,32,60,117,115,101,114,84,97,115,107,32,97,99,116,105,118,105,116,105,58,97,115,115,105,103,110,101,101,61,34,36,123,112,109,105,115,80,117,98,108,105,99,65,99,116,105,118,105,116,105,46,105,110,105,116,105,97,116,111,114,125,34,32,97,99,116,105,118,105,116,105,58,101,120,99,108,117,115,105,118,101,61,34,116,114,117,101,34,32,105,100,61,34,105,110,105,116,105,97,116,111,114,34,32,110,97,109,101,61,34,-27,-113,-111,-24,-75,-73,-24,-128,-123,34,47,62,13,10,32,32,32,32,60,117,115,101,114,84,97,115,107,32,97,99,116,105,118,105,116,105,58,97,115,115,105,103,110,101,101,61,34,36,123,112,109,105,115,80,117,98,108,105,99,65,99,116,105,118,105,116,105,46,115,117,112,101,114,105,111,114,125,34,32,97,99,116,105,118,105,116,105,58,101,120,99,108,117,115,105,118,101,61,34,116,114,117,101,34,32,105,100,61,34,115,117,112,101,114,105,111,114,34,32,110,97,109,101,61,34,-25,-101,-76,-25,-70,-65,-28,-72,-118,-25,-70,-89,34,47,62,13,10,32,32,32,32,60,117,115,101,114,84,97,115,107,32,97,99,116,105,118,105,116,105,58,97,115,115,105,103,110,101,101,61,34,36,123,112,109,105,115,80,117,98,108,105,99,65,99,116,105,118,105,116,105,46,100,105,114,101,99,116,111,114,125,34,32,97,99,116,105,118,105,116,105,58,101,120,99,108,117,115,105,118,101,61,34,116,114,117,101,34,32,105,100,61,34,100,105,114,101,99,116,111,114,34,32,110,97,109,101,61,34,-23,-125,-88,-23,-105,-88,-28,-72,-69,-25,-82,-95,34,47,62,13,10,32,32,32,32,60,101,110,100,69,118,101,110,116,32,105,100,61,34,101,110,100,34,32,110,97,109,101,61,34,-25,-69,-109,-26,-99,-97,34,47,62,13,10,32,32,32,32,60,115,101,113,117,101,110,99,101,70,108,111,119,32,105,100,61,34,95,55,34,32,115,111,117,114,99,101,82,101,102,61,34,115,116,97,114,116,34,32,116,97,114,103,101,116,82,101,102,61,34,105,110,105,116,105,97,116,111,114,34,47,62,13,10,32,32,32,32,60,115,101,113,117,101,110,99,101,70,108,111,119,32,105,100,61,34,95,56,34,32,115,111,117,114,99,101,82,101,102,61,34,105,110,105,116,105,97,116,111,114,34,32,116,97,114,103,101,116,82,101,102,61,34,115,117,112,101,114,105,111,114,34,47,62,13,10,32,32,32,32,60,115,101,113,117,101,110,99,101,70,108,111,119,32,105,100,61,34,95,57,34,32,115,111,117,114,99,101,82,101,102,61,34,115,117,112,101,114,105,111,114,34,32,116,97,114,103,101,116,82,101,102,61,34,100,105,114,101,99,116,111,114,34,47,62,13,10,32,32,32,32,60,115,101,113,117,101,110,99,101,70,108,111,119,32,105,100,61,34,95,49,48,34,32,115,111,117,114,99,101,82,101,102,61,34,100,105,114,101,99,116,111,114,34,32,116,97,114,103,101,116,82,101,102,61,34,101,110,100,34,47,62,13,10,32,32,32,32,60,101,120,99,108,117,115,105,118,101,71,97,116,101,119,97,121,32,103,97,116,101,119,97,121,68,105,114,101,99,116,105,111,110,61,34,85,110,115,112,101,99,105,102,105,101,100,34,32,105,100,61,34,97,103,114,101,101,69,120,99,108,117,115,105,118,101,71,97,116,101,119,97,121,34,32,110,97,109,101,61,34,-28,-72,-115,-27,-112,-116,-26,-124,-113,34,47,62,13,10,32,32,32,32,60,115,101,113,117,101,110,99,101,70,108,111,119,32,105,100,61,34,95,51,34,32,115,111,117,114,99,101,82,101,102,61,34,115,117,112,101,114,105,111,114,34,32,116,97,114,103,101,116,82,101,102,61,34,97,103,114,101,101,69,120,99,108,117,115,105,118,101,71,97,116,101,119,97,121,34,62,13,10,32,32,32,32,32,32,60,99,111,110,100,105,116,105,111,110,69,120,112,114,101,115,115,105,111,110,32,120,115,105,58,116,121,112,101,61,34,116,70,111,114,109,97,108,69,120,112,114,101,115,115,105,111,110,34,62,13,10,32,32,32,32,32,32,32,32,60,33,91,67,68,65,84,65,91,36,123,112,109,105,115,80,117,98,108,105,99,65,99,116,105,118,105,116,105,46,97,117,100,105,116,61,61,116,114,117,101,125,93,93,62,13,10,32,32,32,32,32,32,60,47,99,111,110,100,105,116,105,111,110,69,120,112,114,101,115,115,105,111,110,62,13,10,32,32,32,32,60,47,115,101,113,117,101,110,99,101,70,108,111,119,62,13,10,32,32,32,32,60,115,101,113,117,101,110,99,101,70,108,111,119,32,105,100,61,34,95,52,34,32,115,111,117,114,99,101,82,101,102,61,34,97,103,114,101,101,69,120,99,108,117,115,105,118,101,71,97,116,101,119,97,121,34,32,116,97,114,103,101,116,82,101,102,61,34,100,105,114,101,99,116,111,114,34,47,62,13,10,32,32,32,32,60,115,101,113,117,101,110,99,101,70,108,111,119,32,105,100,61,34,95,53,34,32,115,111,117,114,99,101,82,101,102,61,34,97,103,114,101,101,69,120,99,108,117,115,105,118,101,71,97,116,101,119,97,121,34,32,116,97,114,103,101,116,82,101,102,61,34,101,110,100,34,62,13,10,32,32,32,32,32,32,60,99,111,110,100,105,116,105,111,110,69,120,112,114,101,115,115,105,111,110,32,120,115,105,58,116,121,112,101,61,34,116,70,111,114,109,97,108,69,120,112,114,101,115,115,105,111,110,34,62,13,10,32,32,32,32,32,32,32,32,60,33,91,67,68,65,84,65,91,36,123,112,109,105,115,80,117,98,108,105,99,65,99,116,105,118,105,116,105,46,97,117,100,105,116,61,61,102,97,108,115,101,125,93,93,62,13,10,32,32,32,32,32,32,60,47,99,111,110,100,105,116,105,111,110,69,120,112,114,101,115,115,105,111,110,62,13,10,32,32,32,32,60,47,115,101,113,117,101,110,99,101,70,108,111,119,62,13,10,32,32,60,47,112,114,111,99,101,115,115,62,13,10,32,32,60,98,112,109,110,100,105,58,66,80,77,78,68,105,97,103,114,97,109,32,100,111,99,117,109,101,110,116,97,116,105,111,110,61,34,98,97,99,107,103,114,111,117,110,100,61,35,51,67,51,70,52,49,59,99,111,117,110,116,61,49,59,104,111,114,105,122,111,110,116,97,108,99,111,117,110,116,61,49,59,111,114,105,101,110,116,97,116,105,111,110,61,48,59,119,105,100,116,104,61,56,52,50,46,52,59,104,101,105,103,104,116,61,49,49,57,53,46,50,59,105,109,97,103,101,97,98,108,101,87,105,100,116,104,61,56,51,50,46,52,59,105,109,97,103,101,97,98,108,101,72,101,105,103,104,116,61,49,49,56,53,46,50,59,105,109,97,103,101,97,98,108,101,88,61,53,46,48,59,105,109,97,103,101,97,98,108,101,89,61,53,46,48,34,32,105,100,61,34,68,105,97,103,114,97,109,45,95,49,34,32,110,97,109,101,61,34,78,101,119,32,68,105,97,103,114,97,109,34,62,13,10,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,80,108,97,110,101,32,98,112,109,110,69,108,101,109,101,110,116,61,34,112,109,105,115,45,112,117,98,108,105,99,45,97,99,116,105,118,105,116,105,34,62,13,10,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,83,104,97,112,101,32,98,112,109,110,69,108,101,109,101,110,116,61,34,115,116,97,114,116,34,32,105,100,61,34,83,104,97,112,101,45,115,116,97,114,116,34,62,13,10,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,51,50,46,48,34,32,119,105,100,116,104,61,34,51,50,46,48,34,32,120,61,34,50,57,53,46,48,34,32,121,61,34,51,53,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,51,50,46,48,34,32,119,105,100,116,104,61,34,51,50,46,48,34,32,120,61,34,48,46,48,34,32,121,61,34,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,83,104,97,112,101,62,13,10,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,83,104,97,112,101,32,98,112,109,110,69,108,101,109,101,110,116,61,34,105,110,105,116,105,97,116,111,114,34,32,105,100,61,34,83,104,97,112,101,45,105,110,105,116,105,97,116,111,114,34,62,13,10,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,53,53,46,48,34,32,119,105,100,116,104,61,34,56,53,46,48,34,32,120,61,34,50,55,53,46,48,34,32,121,61,34,49,50,53,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,53,53,46,48,34,32,119,105,100,116,104,61,34,56,53,46,48,34,32,120,61,34,48,46,48,34,32,121,61,34,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,83,104,97,112,101,62,13,10,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,83,104,97,112,101,32,98,112,109,110,69,108,101,109,101,110,116,61,34,115,117,112,101,114,105,111,114,34,32,105,100,61,34,83,104,97,112,101,45,115,117,112,101,114,105,111,114,34,62,13,10,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,53,53,46,48,34,32,119,105,100,116,104,61,34,56,53,46,48,34,32,120,61,34,50,55,53,46,48,34,32,121,61,34,50,51,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,53,53,46,48,34,32,119,105,100,116,104,61,34,56,53,46,48,34,32,120,61,34,48,46,48,34,32,121,61,34,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,83,104,97,112,101,62,13,10,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,83,104,97,112,101,32,98,112,109,110,69,108,101,109,101,110,116,61,34,100,105,114,101,99,116,111,114,34,32,105,100,61,34,83,104,97,112,101,45,100,105,114,101,99,116,111,114,34,62,13,10,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,53,53,46,48,34,32,119,105,100,116,104,61,34,56,53,46,48,34,32,120,61,34,50,56,48,46,48,34,32,121,61,34,51,52,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,53,53,46,48,34,32,119,105,100,116,104,61,34,56,53,46,48,34,32,120,61,34,48,46,48,34,32,121,61,34,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,83,104,97,112,101,62,13,10,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,83,104,97,112,101,32,98,112,109,110,69,108,101,109,101,110,116,61,34,101,110,100,34,32,105,100,61,34,83,104,97,112,101,45,101,110,100,34,62,13,10,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,51,50,46,48,34,32,119,105,100,116,104,61,34,51,50,46,48,34,32,120,61,34,51,48,53,46,48,34,32,121,61,34,52,52,53,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,51,50,46,48,34,32,119,105,100,116,104,61,34,51,50,46,48,34,32,120,61,34,48,46,48,34,32,121,61,34,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,83,104,97,112,101,62,13,10,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,83,104,97,112,101,32,98,112,109,110,69,108,101,109,101,110,116,61,34,97,103,114,101,101,69,120,99,108,117,115,105,118,101,71,97,116,101,119,97,121,34,32,105,100,61,34,83,104,97,112,101,45,97,103,114,101,101,69,120,99,108,117,115,105,118,101,71,97,116,101,119,97,121,34,32,105,115,77,97,114,107,101,114,86,105,115,105,98,108,101,61,34,102,97,108,115,101,34,62,13,10,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,51,50,46,48,34,32,119,105,100,116,104,61,34,51,50,46,48,34,32,120,61,34,54,53,46,48,34,32,121,61,34,51,48,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,51,50,46,48,34,32,119,105,100,116,104,61,34,51,50,46,48,34,32,120,61,34,48,46,48,34,32,121,61,34,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,83,104,97,112,101,62,13,10,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,69,100,103,101,32,98,112,109,110,69,108,101,109,101,110,116,61,34,95,51,34,32,105,100,61,34,66,80,77,78,69,100,103,101,95,95,51,34,32,115,111,117,114,99,101,69,108,101,109,101,110,116,61,34,115,117,112,101,114,105,111,114,34,32,116,97,114,103,101,116,69,108,101,109,101,110,116,61,34,97,103,114,101,101,69,120,99,108,117,115,105,118,101,71,97,116,101,119,97,121,34,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,50,55,53,46,48,34,32,121,61,34,50,53,53,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,50,48,48,46,48,34,32,121,61,34,50,53,53,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,57,55,46,48,34,32,121,61,34,51,49,54,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,48,46,48,34,32,119,105,100,116,104,61,34,48,46,48,34,32,120,61,34,48,46,48,34,32,121,61,34,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,69,100,103,101,62,13,10,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,69,100,103,101,32,98,112,109,110,69,108,101,109,101,110,116,61,34,95,52,34,32,105,100,61,34,66,80,77,78,69,100,103,101,95,95,52,34,32,115,111,117,114,99,101,69,108,101,109,101,110,116,61,34,97,103,114,101,101,69,120,99,108,117,115,105,118,101,71,97,116,101,119,97,121,34,32,116,97,114,103,101,116,69,108,101,109,101,110,116,61,34,100,105,114,101,99,116,111,114,34,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,57,55,46,48,34,32,121,61,34,51,49,54,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,50,53,48,46,48,34,32,121,61,34,51,51,53,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,50,56,48,46,48,34,32,121,61,34,51,54,55,46,53,34,47,62,13,10,32,32,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,48,46,48,34,32,119,105,100,116,104,61,34,48,46,48,34,32,120,61,34,48,46,48,34,32,121,61,34,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,69,100,103,101,62,13,10,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,69,100,103,101,32,98,112,109,110,69,108,101,109,101,110,116,61,34,95,53,34,32,105,100,61,34,66,80,77,78,69,100,103,101,95,95,53,34,32,115,111,117,114,99,101,69,108,101,109,101,110,116,61,34,97,103,114,101,101,69,120,99,108,117,115,105,118,101,71,97,116,101,119,97,121,34,32,116,97,114,103,101,116,69,108,101,109,101,110,116,61,34,101,110,100,34,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,57,55,46,48,34,32,121,61,34,51,49,54,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,50,48,48,46,48,34,32,121,61,34,51,57,53,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,51,48,53,46,48,34,32,121,61,34,52,54,49,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,48,46,48,34,32,119,105,100,116,104,61,34,48,46,48,34,32,120,61,34,48,46,48,34,32,121,61,34,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,69,100,103,101,62,13,10,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,69,100,103,101,32,98,112,109,110,69,108,101,109,101,110,116,61,34,95,55,34,32,105,100,61,34,66,80,77,78,69,100,103,101,95,95,55,34,32,115,111,117,114,99,101,69,108,101,109,101,110,116,61,34,115,116,97,114,116,34,32,116,97,114,103,101,116,69,108,101,109,101,110,116,61,34,105,110,105,116,105,97,116,111,114,34,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,51,49,49,46,48,34,32,121,61,34,54,55,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,51,49,49,46,48,34,32,121,61,34,49,50,53,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,48,46,48,34,32,119,105,100,116,104,61,34,48,46,48,34,32,120,61,34,48,46,48,34,32,121,61,34,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,69,100,103,101,62,13,10,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,69,100,103,101,32,98,112,109,110,69,108,101,109,101,110,116,61,34,95,56,34,32,105,100,61,34,66,80,77,78,69,100,103,101,95,95,56,34,32,115,111,117,114,99,101,69,108,101,109,101,110,116,61,34,105,110,105,116,105,97,116,111,114,34,32,116,97,114,103,101,116,69,108,101,109,101,110,116,61,34,115,117,112,101,114,105,111,114,34,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,51,49,55,46,53,34,32,121,61,34,49,56,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,51,49,55,46,53,34,32,121,61,34,50,51,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,48,46,48,34,32,119,105,100,116,104,61,34,48,46,48,34,32,120,61,34,48,46,48,34,32,121,61,34,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,69,100,103,101,62,13,10,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,69,100,103,101,32,98,112,109,110,69,108,101,109,101,110,116,61,34,95,57,34,32,105,100,61,34,66,80,77,78,69,100,103,101,95,95,57,34,32,115,111,117,114,99,101,69,108,101,109,101,110,116,61,34,115,117,112,101,114,105,111,114,34,32,116,97,114,103,101,116,69,108,101,109,101,110,116,61,34,100,105,114,101,99,116,111,114,34,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,51,50,48,46,48,34,32,121,61,34,50,56,53,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,51,50,48,46,48,34,32,121,61,34,51,52,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,48,46,48,34,32,119,105,100,116,104,61,34,48,46,48,34,32,120,61,34,48,46,48,34,32,121,61,34,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,69,100,103,101,62,13,10,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,69,100,103,101,32,98,112,109,110,69,108,101,109,101,110,116,61,34,95,49,48,34,32,105,100,61,34,66,80,77,78,69,100,103,101,95,95,49,48,34,32,115,111,117,114,99,101,69,108,101,109,101,110,116,61,34,100,105,114,101,99,116,111,114,34,32,116,97,114,103,101,116,69,108,101,109,101,110,116,61,34,101,110,100,34,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,51,50,49,46,48,34,32,121,61,34,51,57,53,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,100,105,58,119,97,121,112,111,105,110,116,32,120,61,34,51,50,49,46,48,34,32,121,61,34,52,52,53,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,32,32,32,32,60,100,99,58,66,111,117,110,100,115,32,104,101,105,103,104,116,61,34,48,46,48,34,32,119,105,100,116,104,61,34,48,46,48,34,32,120,61,34,48,46,48,34,32,121,61,34,48,46,48,34,47,62,13,10,32,32,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,76,97,98,101,108,62,13,10,32,32,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,69,100,103,101,62,13,10,32,32,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,80,108,97,110,101,62,13,10,32,32,60,47,98,112,109,110,100,105,58,66,80,77,78,68,105,97,103,114,97,109,62,13,10,60,47,100,101,102,105,110,105,116,105,111,110,115,62,13,10],"deploymentId":"b90c6abf-3e70-11eb-bf2c-b42e9973014d","name":"processes/pmisPublicActiviti.bpmn","persistentState":"org.activiti.engine.impl.persistence.entity.ResourceEntityImpl","id":"b90c6ac0-3e70-11eb-bf2c-b42e9973014d","updated":false}},"persistentState":{"tenantId":""},"deleted":false,"inserted":true,"name":"PMIS通用审批流程","tenantId":"","id":"b90c6abf-3e70-11eb-bf2c-b42e9973014d","updated":false,"deploymentTime":1607993942679}
//        {"deployID":"b90c6abf-3e70-11eb-bf2c-b42e9973014d","deployName":"PMIS通用审批流程"}
    }

    /**
     * 启动流程
     */
    @Test
    public void startInstance() {
        securityUtil.logInAs("salaboy");
        HashMap<String, Object> variable = new HashMap<>();
        variable.put("initiator", "张三");
        variable.put("superior", "李四");
        variable.put("director", "王五");
        variable.put("audit", true);
        String businessKey = "pmis_10002";
        ProcessInstance processInstance = processRuntime.start(
                ProcessPayloadBuilder
                        .start()
                        .withProcessDefinitionKey("pmis-public-activiti")
                        .withName("pmis_10002审批流程")
                        .withVariables(variable)
                        .withBusinessKey(businessKey)
                        .build());


        System.out.println("启动流程JSON：" + JSON.toJSON(processInstance));
        System.out.println("processInstanceId：" + processInstance.getId());
        System.out.println("processDefinitionKey：" + processInstance.getProcessDefinitionKey());
        System.out.println("businessKey：" + processInstance.getBusinessKey());
//        启动流程JSON：{"processDefinitionId":"pmis-public-activiti:1:b926f7a1-3e70-11eb-bf2c-b42e9973014d","initiator":"salaboy","businessKey":"pmis_10001","name":"XXX审批流程","id":"c8d23297-3e70-11eb-8977-b42e9973014d","processDefinitionVersion":1,"startDate":1607993969141,"processDefinitionKey":"pmis-public-activiti","status":"RUNNING"}
//        processInstanceId：c8d23297-3e70-11eb-8977-b42e9973014d
//        processDefinitionKey：pmis-public-activiti
//        businessKey：pmis_10001
    }

    /**
     * 获取流程分页数据
     */
    @Test
    public void listInstance() {
        securityUtil.logInAs("salaboy");
        String businessKey = "pmis_10001";
        GetProcessInstancesPayload getProcessInstancesPayload = new GetProcessInstancesPayload();
        getProcessInstancesPayload.setBusinessKey(businessKey);
        Page<ProcessInstance> processInstancePage = processRuntime.processInstances(Pageable.of(0, 10), getProcessInstancesPayload);
        System.out.println("获取流程分页数据：" + JSON.toJSONString(processInstancePage));
        System.out.println("获取流程总条数：" + processInstancePage.getTotalItems());
        for (ProcessInstance processInstance : processInstancePage.getContent()) {
            System.out.println("流程数据：" + JSON.toJSON(processInstance));
            System.out.println("业务关联编号：" + processInstance.getBusinessKey());
        }
//        获取流程分页数据：{"content":[{"businessKey":"pmis_10001","id":"c8d23297-3e70-11eb-8977-b42e9973014d","initiator":"salaboy","name":"XXX审批流程","processDefinitionId":"pmis-public-activiti:1:b926f7a1-3e70-11eb-bf2c-b42e9973014d","processDefinitionKey":"pmis-public-activiti","processDefinitionVersion":1,"startDate":1607993969141,"status":"RUNNING"}],"totalItems":1}
//        获取流程总条数：1
//        流程数据：{"processDefinitionId":"pmis-public-activiti:1:b926f7a1-3e70-11eb-bf2c-b42e9973014d","initiator":"salaboy","businessKey":"pmis_10001","name":"XXX审批流程","id":"c8d23297-3e70-11eb-8977-b42e9973014d","processDefinitionVersion":1,"startDate":1607993969141,"processDefinitionKey":"pmis-public-activiti","status":"RUNNING"}
//        业务关联编号：pmis_10001
    }

    /**
     * 查询流程历史步骤
     */
    @Test
    public void listHistoricActivityInstance() {
        try {
            String processInstanceId = "c8d23297-3e70-11eb-8977-b42e9973014d";
            List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery()
                    .processInstanceId(processInstanceId).orderByHistoricActivityInstanceStartTime().asc().list();
            if (list != null && list.size() > 0) {
                System.out.println("流程历史步骤：" + JSON.toJSON(list));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
//        流程历史步骤：[{"processDefinitionId":"pmis-public-activiti:1:b926f7a1-3e70-11eb-bf2c-b42e9973014d","processInstanceId":"c8d23297-3e70-11eb-8977-b42e9973014d","durationInMillis":3,"activityName":"开始","persistentState":{"executionId":"c8d789cb-3e70-11eb-8977-b42e9973014d","endTime":1607993969181,"durationInMillis":3},"activityId":"start","executionId":"c8d789cb-3e70-11eb-8977-b42e9973014d","deleted":false,"inserted":false,"tenantId":"","startTime":1607993969178,"endTime":1607993969181,"id":"c8d7d7ec-3e70-11eb-8977-b42e9973014d","time":1607993969178,"activityType":"startEvent","updated":false},{"processDefinitionId":"pmis-public-activiti:1:b926f7a1-3e70-11eb-bf2c-b42e9973014d","processInstanceId":"c8d23297-3e70-11eb-8977-b42e9973014d","activityName":"发起者","persistentState":{"executionId":"c8d789cb-3e70-11eb-8977-b42e9973014d","assignee":"张三"},"activityId":"initiator","executionId":"c8d789cb-3e70-11eb-8977-b42e9973014d","deleted":false,"inserted":false,"tenantId":"","startTime":1607993969183,"assignee":"张三","id":"c8d89b3d-3e70-11eb-8977-b42e9973014d","time":1607993969183,"activityType":"userTask","updated":false,"taskId":"c8dae52e-3e70-11eb-8977-b42e9973014d"}]
    }

    /**
     * 查询流程执行任务记录
     */
    @Test
    public void listHistoricTaskInstance() {
        String processInstanceId = "c8d23297-3e70-11eb-8977-b42e9973014d";
        List<HistoricTaskInstance> historicTaskInstanceList = historyService.createHistoricTaskInstanceQuery()
                .processInstanceId(processInstanceId)
                .orderByHistoricTaskInstanceStartTime().asc()
                .list();
        System.out.println("查询流程执行任务记录响应数据：" + JSON.toJSON(historicTaskInstanceList));
//        查询流程执行任务记录响应数据：[{"taskLocalVariables":{},"persistentState":{"taskDefinitionKey":"initiator","processDefinitionId":"pmis-public-activiti:1:b926f7a1-3e70-11eb-bf2c-b42e9973014d","name":"发起者","assignee":"张三","priority":50},"inserted":false,"startTime":1607993969198,"id":"c8dae52e-3e70-11eb-8977-b42e9973014d","processDefinitionId":"pmis-public-activiti:1:b926f7a1-3e70-11eb-bf2c-b42e9973014d","processInstanceId":"c8d23297-3e70-11eb-8977-b42e9973014d","priority":50,"executionId":"c8d789cb-3e70-11eb-8977-b42e9973014d","taskDefinitionKey":"initiator","deleted":false,"createTime":1607993969198,"name":"发起者","tenantId":"","assignee":"张三","time":1607993969198,"processVariables":{},"updated":false}]
    }

    /**
     * 查询流程历史变量
     */
    @Test
    public void listHistoricVariableInstance() {
        String processInstanceId = "c8d23297-3e70-11eb-8977-b42e9973014d";
        List<HistoricVariableInstance> historicVariableInstanceList = historyService.createHistoricVariableInstanceQuery()
                .processInstanceId(processInstanceId).list();
        System.out.println("查询流程历史变量响应数据：" + JSON.toJSON(historicVariableInstanceList));
//        查询流程历史变量响应数据：[{"variableTypeName":"json","byteArrayRef":{"deleted":false},"persistentState":{"textValue":"{\"initiator\":\"张三\",\"superior\":\"李四\",\"director\":\"王五\",\"audit\":null}","createTime":1607993969175,"lastUpdatedTime":1607993969175},"variableType":{"typeName":"json","cachable":true},"inserted":false,"lastUpdatedTime":1607993969175,"revisionNext":1,"id":"c8d762b9-3e70-11eb-8977-b42e9973014d","value":{"integralNumber":false,"double":false,"valueNode":false,"bigInteger":false,"floatingPointNumber":false,"float":false,"nodeType":"OBJECT","int":false,"long":false,"textual":false,"empty":false,"missingNode":false,"pojo":false,"number":false,"boolean":false,"null":false,"array":false,"binary":false,"containerNode":true,"short":false,"bigDecimal":false,"object":true},"processInstanceId":"c8d23297-3e70-11eb-8977-b42e9973014d","variableName":"pmisPublicActiviti","textValue":"{\"initiator\":\"张三\",\"superior\":\"李四\",\"director\":\"王五\",\"audit\":null}","revision":0,"executionId":"c8d23297-3e70-11eb-8977-b42e9973014d","deleted":false,"createTime":1607993969175,"cachedValue":{"integralNumber":false,"double":false,"valueNode":false,"bigInteger":false,"floatingPointNumber":false,"float":false,"nodeType":"OBJECT","int":false,"long":false,"textual":false,"empty":false,"missingNode":false,"pojo":false,"number":false,"boolean":false,"null":false,"array":false,"binary":false,"containerNode":true,"short":false,"bigDecimal":false,"object":true},"name":"pmisPublicActiviti","time":1607993969175,"updated":false},{"variableTypeName":"json","byteArrayRef":{"deleted":false},"persistentState":{"textValue":"{\"initiator\":\"张三\",\"superior\":\"李四\",\"director\":\"王五\",\"audit\":null}","createTime":1607993969202,"lastUpdatedTime":1607993969202},"variableType":{"typeName":"json","cachable":true},"inserted":false,"lastUpdatedTime":1607993969202,"revisionNext":1,"id":"c8db816f-3e70-11eb-8977-b42e9973014d","value":{"integralNumber":false,"double":false,"valueNode":false,"bigInteger":false,"floatingPointNumber":false,"float":false,"nodeType":"OBJECT","int":false,"long":false,"textual":false,"empty":false,"missingNode":false,"pojo":false,"number":false,"boolean":false,"null":false,"array":false,"binary":false,"containerNode":true,"short":false,"bigDecimal":false,"object":true},"processInstanceId":"c8d23297-3e70-11eb-8977-b42e9973014d","variableName":"pmisPublicActiviti","textValue":"{\"initiator\":\"张三\",\"superior\":\"李四\",\"director\":\"王五\",\"audit\":null}","revision":0,"executionId":"c8d789cb-3e70-11eb-8977-b42e9973014d","deleted":false,"createTime":1607993969202,"cachedValue":{"integralNumber":false,"double":false,"valueNode":false,"bigInteger":false,"floatingPointNumber":false,"float":false,"nodeType":"OBJECT","int":false,"long":false,"textual":false,"empty":false,"missingNode":false,"pojo":false,"number":false,"boolean":false,"null":false,"array":false,"binary":false,"containerNode":true,"short":false,"bigDecimal":false,"object":true},"name":"pmisPublicActiviti","time":1607993969202,"updated":false,"taskId":"c8dae52e-3e70-11eb-8977-b42e9973014d"}]

    }

    /**
     * 查询任务分页数据
     */
    @Test
    public void listTaskPage() {
        String userName = "张三";
        securityUtil.logInAs(userName);
        String processInstanceId = "c8d23297-3e70-11eb-8977-b42e9973014d";
        GetTasksPayload getTasksPayload = new GetTasksPayload();
        getTasksPayload.setProcessInstanceId(processInstanceId);
        Page<Task> taskPage = taskRuntime.tasks(Pageable.of(0, 10), getTasksPayload);
        System.out.println(JSON.toJSON(taskPage));
        if (taskPage.getTotalItems() == 0) {
            System.out.println("暂无任何任务");
        }
        for (Task task : taskPage.getContent()) {
            System.out.println("任务：" + JSON.toJSON(task));
        }
//        {"totalItems":1,"content":[{"processDefinitionId":"pmis-public-activiti:1:b926f7a1-3e70-11eb-bf2c-b42e9973014d","processInstanceId":"c8d23297-3e70-11eb-8977-b42e9973014d","priority":50,"createdDate":1607993969183,"name":"发起者","assignee":"张三","id":"c8dae52e-3e70-11eb-8977-b42e9973014d","status":"ASSIGNED"}]}
//        任务：{"processDefinitionId":"pmis-public-activiti:1:b926f7a1-3e70-11eb-bf2c-b42e9973014d","processInstanceId":"c8d23297-3e70-11eb-8977-b42e9973014d","priority":50,"createdDate":1607993969183,"name":"发起者","assignee":"张三","id":"c8dae52e-3e70-11eb-8977-b42e9973014d","status":"ASSIGNED"}
    }


    /**
     * 完成任务
     */
    @Test
    public void task() {
        String userName = "张三";
        securityUtil.logInAs(userName);
        String processInstanceId = "b2b34c84-3dd7-11eb-a752-b42e9973014d";
        GetTasksPayload getTasksPayload = new GetTasksPayload();
        getTasksPayload.setProcessInstanceId(processInstanceId);
        Page<Task> taskPage = taskRuntime.tasks(Pageable.of(0, 10), getTasksPayload);
        if (taskPage.getTotalItems() <= 0) {
            System.out.println("暂无任何任务");
        }
        for (Task task : taskPage.getContent()) {
            System.out.println("任务：" + JSON.toJSON(task));
            if (userName.equals(task.getAssignee())) {
//                // 拾取任务
//                taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
//                System.out.println("拾取任务成功");
                // 完成任务
                CompleteTaskPayload build = TaskPayloadBuilder.complete().withTaskId(task.getId()).build();
                taskRuntime.complete(build);
                System.out.println("完成任务");
                break;
            }
        }
    }


}
